<!-- 商品评价 -->
<template>
	<view class="page">
		<!-- 评价类型 -->
		<FilterTag></FilterTag>
		<!-- 列表 -->
		<List v-if="list.length"></List>
		
		<!-- 暂无数据 -->
		<c-empty-data v-if="!list.length && !loadingState.default"></c-empty-data>
		<!-- loading -->
		<view style="margin-top: 20rpx;">
			<c-loading :loadingState="loadingState"></c-loading>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import FilterTag from './components/filter-tag.vue';
	import List from './components/list.vue';
	
	uni.setNavigationBarTitle({
		title: '商品评价(652)'
	});
	
	const params = ref({
		page: 1,
		limit: 10,
	});
	const list = ref([]);
	const total = ref(0);
	const loadingState = ref({
		default: false,
		loading: false,
		stop: false,
		pullup: false,
	});
	
	loadingState.value.default = true;
	setTimeout(() => {
		list.value = [{}];
		loadingState.value.default = false;
		loadingState.value.stop = true;
	}, 1000);
	
	// 获取列表
	const getList = async () => {
		// 正在加载中并且不是第一页，或者已经加载完所有了
		if ((loadingState.value.default && params.value.page !== 1) || (loadingState.value.stop && params.value.page > 1)) return;
		loadingState.value.default = true;
		loadingState.value.pullup = false;
		loadingState.value.stop = false;
	
		const res = await api.order_api.getList(params.value);
		total.value = res.data.data.count;
		const list = res.data.data.list;
	
		if (params.value.page === 1) {
			list.value = list;
		} else {
			list.value.push(...list);
		}
	
		loadingState.value.default = false;
		if (list.value.length < recordTotal) {
			loadingState.value.pullup = true;
		} else if (recordTotal === 0) {
			loadingState.value.stop = false;
		} else {
			loadingState.value.stop = true;
		}
	
		params.value.page += 1;
	}
</script>

<style lang="scss" scoped>
	
</style>